package Polymorphism05;


interface JD{

}

abstract class Animal{

}

class Dog extends Animal implements JD{

}

class Sheep extends Animal{

}
public class Demo {
    public static void main(String[] args) {
        //1.普通类
        Dog dog = new Dog();
        boolean b = dog instanceof Dog; // instanceof检测 dog(引用变量名)引用指向的对象能否赋值给运算符右边的 Dog(类名)
        //相当于判定 Dog temp =new Dog() 是否成立,成立返回true,否则返回false
        System.out.println(b);//true

        System.out.println(new Dog() instanceof Dog);//true

        System.out.println("----------------------------");

        //2.抽象类
        Animal a = new Dog();
        System.out.println(a instanceof Dog); //相当于判定 Dog temp =new Dog()  true
        System.out.println(a instanceof Animal);//相当于判定Animal temp =new Dog() true

        System.out.println("----------------------------");

        //3.接口
        JD j = new Dog();
        System.out.println(j instanceof Dog);//true 相当于判定 Dog temp = new Dog()
        System.out.println(j instanceof JD);//true  相当于判定 JD temp= new Dog()

        System.out.println("----------------------------");

        //4.其它类
        Animal a2 = new Sheep();
        System.out.println(a2 instanceof Dog);//false 相当于判定 Dog temp = new Sheep() 不成立false

    }
}
